<template>
	<view>
		<view class="scroll-view_H">
			<view class="scroll-view-item_H" v-for="(item,index) in detail">
				<view class="co-up">
					<!-- <image :src="common.appUrl.oss+common.imgList.sc16"></image> -->
					<view class="juti">
						<view class="ti1">全平台商家通用</view>
						<view class="ti2">{{item.price}}<text class="ts1">元</text> <text class="ts2">x</text>
							{{item.num}}<text class="ts1">张</text>
						</view>
						<view class="ti3">无门槛</view>
						<view class="ti4">全平台通用</view>
					</view>
				</view>
				<view class="co-down">
					<view class="co-money">￥{{item.vip_price}}<text>￥{{item.market_price}}</text></view>
					<view class="co-qg" @click="handlePay(item.id)">抢购</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		mapState,
	} from 'vuex';
	export default {
		computed: {
			...mapState(['common'])
		},
		data() {
			return {
				app: getApp().globalData,
				detail: [],
				state: 0
			}
		},

		onLoad(e) {
			this.state = e.state
			this.app.post('/api/user/conpon_list').then(res => {
				console.log(res)
				this.detail = res
			})
		},
		methods: {
			handlePay(id) {
				if(this.state==0){
					uni.showToast({
						title: '请先开通会员',
						icon: "none"
					})
					return
				}
				this.app.post('/api/user/conpon_pay', {
					id: id
				}).then(res => {
					console.log(res)
					uni.requestPayment({
						appId: res.pay_param.appId,
						nonceStr: res.pay_param.nonceStr,
						package: res.pay_param.package,
						paySign: res.pay_param.paySign,
						signType: res.pay_param.signType,
						timeStamp: res.pay_param.timeStamp,
						success: (e) => {
							uni.showToast({
								title: '支付成功',
								icon: "none"
							})
						},
						fail: (e) => {
							uni.showToast({
								title: '支付失败',
								icon: "none"
							})
						}
					})
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #FFFFFF;
	}

	.scroll-view_H {
		width: 690rpx;
		margin-left: 30rpx;
		display: flex;
		justify-content: space-between;
		flex-wrap: wrap;

		.scroll-view-item_H {
			width: 328rpx;
			margin-top: 30rpx;

			.co-up {
				width: 328rpx;
				height: 170rpx;
				display: flex;
				flex-wrap: wrap;
				justify-content: center;
				position: relative;

				image {
					width: 328rpx;
					height: 170rpx;
				}

				.juti {
					position: absolute;
					width: 328rpx;
					height: 170rpx;
					left: 0;
					display: flex;
					flex-wrap: wrap;
					justify-content: center;
					top: 0;
					background-color: #FEF7E5;
					border-radius: 20rpx;
					overflow: hidden;

					.ti1 {
						width: 240rpx;
						text-align: center;
						font-size: 20rpx;
						color: #9B5114;
						line-height: 30rpx;
						background-color: #FEE3AE;
					}

					.ti2 {
						width: 100%;
						text-align: center;
						font-size: 36rpx;
						color: #9B5114;

						.ts1 {
							font-size: 22rpx;
						}

						.ts2 {
							font-size: 22rpx;
							color: #CCAD8E;
						}
					}

					.ti3 {
						width: 100%;
						text-align: center;
						font-size: 20rpx;
						color: #9B5114;
					}

					.ti4 {
						width: 100%;
						text-align: center;
						font-size: 24rpx;
						color: #9B5114;
						line-height: 54rpx;
						background-color: #FEE3AE;
					}
				}
			}

			.co-down {
				width: 100%;
				display: flex;
				justify-content: space-between;
				align-items: center;
				margin-top: 16rpx;

				.co-money {
					color: #9B5114;
					font-size: 36rpx;

					text {
						color: #999999;
						font-size: 24rpx;
						margin-left: 10rpx;
						text-decoration: line-through;
					}
				}

				.co-qg {
					width: 83rpx;
					height: 42rpx;
					border-radius: 50rpx;
					display: flex;
					justify-content: center;
					align-items: center;
					color: #FFFFFF;
					font-size: 24rpx;
					background: linear-gradient(270deg, #DB7C3B 0%, #E69850 100%);
				}
			}
		}
	}
</style>